package com.igeek.user.dao;

import com.igeek.user.entity.User;

import java.util.List;

public class UserDaoImpl extends BaseDao<User> implements IDao<User> {

    @Override
    public User selectOne(User user) {
        User bean = this.getBean(User.class, "select * from t_user where name = ? and pwd = ?", user.getName(), user.getPwd());
        return bean;
    }

    @Override
    public int insert(User user) {
        int count = this.update("insert into t_user values(null,?,?,?,?)", user.getName(), user.getPwd(), user.getAge(), user.getSex());
        System.out.println(count > 0 ? "插入成功" : "插入失败");
        return count;
    }

    @Override
    public List<User> selectAll(String query) {
        List<User> userList = this.getBeanList(User.class, "select * from t_user where name like concat('%', ? ,'%')", query);
        return userList;
    }
}
